package wang.walkline.remotewol;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;

public class DeviceItemAdapter extends ArrayAdapter {
    private final int resourceID;

    public DeviceItemAdapter(Context context, int resource, List<DeviceItem> objects) {
        super(context, resource, objects);
        resourceID = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DeviceItem deviceItem = (DeviceItem) getItem(position); // 获取当前项的Fruit实例
        View view = LayoutInflater.from(getContext()).inflate(resourceID, null);//实例化一个对象
        ImageView image = (ImageView) view.findViewById(R.id.item_image);//获取该布局内的图片视图
        TextView bssid = (TextView) view.findViewById(R.id.item_bssid);//获取该布局内的文本视图
        TextView ssid = (TextView) view.findViewById(R.id.item_ssid);
        image.setImageResource(deviceItem.getImageId());//为图片视图设置图片资源
        bssid.setText(deviceItem.getBSSID());//为文本视图设置文本内容
        ssid.setText(deviceItem.getSSID());

        return view;
    }
}
